/*************************************************************************
 * File Name:    2762.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sun 27 Oct 2013 05:21:25 PM CST
 * 
 * Description:  http://poj.org/problem?id=2762
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

#define MAXN 1010
#define MAXM 6010

struct edge_node {
    int v, next;
};

bool visited[MAXN], instack[MAXN];
struct edge_node edge[MAXM];
int edge_cnt, depth;
int low_link[MAXN], dfn[MAXN], head[MAXN];
int comp[MAXN], comp_cnt;
stack<int> s;

inline void
init_data(void)
{
    memset(head, -1, sizeof(head));
    memset(low_link, -1, sizeof(low_link));
    memset(dfn, -1, sizeof(dfn));
    memset(comp, -1, sizeof(comp));
    memset(visited, false, sizeof(visited));
    memset(instack, false, sizeof(instack));
    edge_cnt = depth = comp_cnt = 0;

    while (!s.empty()) s.pop();
}

inline void
add_edge(int u, int v)
{
    edge[edge_cnt].v = v;
    edge[edge_cnt].next = head[u];
    head[u] = edge_cnt++;
}

void
tarjan_scc(int v)
{
    visited[v] = true;
    low_link[v] = dfn[v] = depth++;
    s.push(v);
    instack[v] = true;

    for (int i = head[v]; i != -1; i = edge[i].next) {
        if (!visited[edge[i].v]) {
            tarjan_scc(edge[i].v);
            low_link[v] = min(low_link[v], low_link[edge[i].v]);
        } else if (instack[edge[i].v]) {
            low_link[v] = min(low_link[v], low_link[edge[i].v]);
        }
    }
    if (low_link[v] == dfn[v]) {
        int u;
        do {
            u = s.top(), s.pop();
            comp[u] = comp_cnt;
            instack[u] = false;
        } while (u != v);
        ++comp_cnt;
    }
}

bool
solve(const vector<vector<bool> > &matrix)
{
    vector<int> degree(comp_cnt, 0);

    for (int i = 0; i < comp_cnt; ++i) {
        for (int j = 0; j < comp_cnt; ++j) {
            if (i != j && matrix[i][j]) {
                ++degree[j];
            }
        }
    }

    int cnt, k;
    vector<bool> used(comp_cnt, false);
    for (int i = 0; i < comp_cnt; ++i) {
        cnt = 0;
        for (int j = 0; j < comp_cnt; ++j) {
            if (!used[j] && degree[j] == 0) {
                ++cnt;
                k = j;
            }
        }
        if (cnt > 1) return false;
        used[k] = true;
        for (int j = 0; j < comp_cnt; ++j) {
            if (matrix[k][j]) --degree[j];
        }
    }
    return true;
}

int
main(int argc, char *argv[])
{
    int T;
    int n, m, u, v;

    scanf("%d", &T);
    while (T--) {
        init_data();
        scanf("%d %d", &n, &m);
        for (int i = 0; i < m; ++i) {
            scanf("%d %d", &u, &v);
            add_edge(u - 1, v - 1);
        }
        for (int i = 0; i < n; ++i) {
            if (visited[i]) continue;
            tarjan_scc(i);
        }
        vector<vector<bool> > matrix(comp_cnt, vector<bool>(comp_cnt, false));


        for (int i = 0; i < n; ++i) {
            for (int j = head[i]; j != -1; j = edge[j].next) {
                matrix[comp[i]][comp[edge[j].v]] = true;
            }
        }

        if (solve(matrix)) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
